package android.microblog;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.microblog.Adapter.UserAdapter;
import android.microblog.Common.Util;
import android.microblog.Data.UserInfo;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.GridView;
import android.widget.LinearLayout;

public class LoginActivity extends Activity implements OnClickListener {

	List<UserInfo> list;
	GridView gridview;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.login);

		LinearLayout layout = (LinearLayout) findViewById(R.id.layout);

		Util.AutoBackground(this, layout, R.drawable.sinaweibo,
				R.drawable.sinaweibo_h);

		gridview = (GridView) findViewById(R.id.grvUsers);
		list = new ArrayList<UserInfo>();
		UserInfo user = new UserInfo();
		user.setId("1");
		user.setUserName("Chet");
		user.setUserIcon(this.getResources().getDrawable(
				R.drawable.male_default));
		list.add(user);
		user = new UserInfo();
		user.setId("2");
		user.setUserName("Chet2");
		user.setUserIcon(this.getResources().getDrawable(
				R.drawable.female_default));
		list.add(user);
		gridview.setAdapter(new UserAdapter(LoginActivity.this, list));

		Button btnLogin = (Button) findViewById(R.id.btnLogin);
		btnLogin.setOnClickListener(this);
		Button btnAdd = (Button) findViewById(R.id.btnAdd);
		btnAdd.setOnClickListener(this);
		Button btnDelete = (Button) findViewById(R.id.btnDelete);
		btnDelete.setOnClickListener(this);
		Button btnExit = (Button) findViewById(R.id.btnExit);
		btnExit.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btnAdd:
			UserInfo userAdd = new UserInfo();
			userAdd.setId("3");
			userAdd.setUserName("Chet3");
			userAdd.setUserIcon(this.getResources().getDrawable(
					R.drawable.male_default));
			list.add(userAdd);
			gridview.setAdapter(new UserAdapter(LoginActivity.this, list));
			break;
		case R.id.btnDelete:
			UserInfo userDel = (UserInfo) this.gridview.getSelectedItem();
			list.remove(userDel);
			gridview.setAdapter(new UserAdapter(LoginActivity.this, list));
			break;
		case R.id.btnLogin:
			break;
		case R.id.btnExit:

			break;

		}
	}
}
